package org.footballmanager.pandafootball.system.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.footballmanager.pandafootball.common.constants.Constants;
import org.footballmanager.pandafootball.system.domain.FootYqts;
import org.footballmanager.pandafootball.system.form.impl.FootYqtsSearchForm;
import org.footballmanager.pandafootball.system.service.FootYqtsService;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Slf4j
@Service
public class FootYqtsServiceImpl extends ServiceImpl<FootYqts> implements FootYqtsService {
    /**
     * 查询
     *
     * @param entityname         实体类名
     * @param map                参数
     * @param footYqtsSearchForm 条件
     */
    @Override
    public void search(String entityname, Model map, FootYqtsSearchForm footYqtsSearchForm) {
        map.addAttribute(String.format(Constants.FORMNAME, entityname), footYqtsSearchForm);
        Page<FootYqts> page = PageHelper.startPage(footYqtsSearchForm.getPageIndex(), footYqtsSearchForm.getPageSize());
        List<FootYqts> list = this.findall(footYqtsSearchForm.buildSearchCommond());
        map.addAttribute(Constants.PI, page.toPageInfo());
        map.addAttribute(String.format(Constants.LISTENTITY, entityname), list);
    }

    /**
     * 删除所有
     *
     * @param footYqtsSearchForm 条件
     * @param request            请求
     */
    @Override
    public void deleteAll(FootYqtsSearchForm footYqtsSearchForm, HttpServletRequest request) {
        if(footYqtsSearchForm.getSelectIds() != null){
            String[] result = footYqtsSearchForm.getSelectIds().split(Constants.COMMA);
            for(String id: result){
                this .delete(Long.parseLong(id), request);
            }
        }
    }
}
